#ifndef _AUTO_DRIVING_H_
#define _AUTO_DRIVING_H_

#include "statemachine.hpp"
#include <Common\Base\hkBase.h>
#include <Common\Base\Math\Vector\hkVector2.h>

class AutoDriving
{
private:
	enum AutoDrivingStates
	{
		BEGIN_STEERING,
		DIRECT_STEERING,
		REVERSE_STEERING,
		EMERGENCY_BRAKE
	};
	typedef Utility::state_machine<AutoDrivingStates>	auto_reverse_state_type;

public: 
	struct Parms
	{
		float CurrentSpeed;
		hkVector2 FollowingPosition;
		bool IsRoadPointOver;

		Parms(void);
	};

	struct Data
	{
		float ReverseSteeringSpeed;
		float ReverseSteeringCheckTime;
		float ReverseSteeringCheckDistance;
		float DirectSteeringSpeed;

		Data(void);
	};

	struct Result
	{
		bool IsReverseRunning;
		bool IsBraking;

		Result(void);
	};


public:
	AutoDriving(void);
	virtual ~AutoDriving(void);

public:
	Result get_result(const Parms& parms, const Data& data);
	inline void ready_go(void) {m_isReadyToGo = true;}
	inline void stop_immediately(void) {m_isReadyToGo = false;}

private:
	void register_states(void);
	bool running_direct(void);
	bool running_reverse(void);
	bool running_begin(void);
	bool braking_state(void);

	void direct_to_reverse(void);
	void reverse_to_direct(void);
	void begin_to_direct(void);
	bool direct_reverse_to_braking(void);
	void braking_to_begin(void);

	void sampling(void);


private:
	auto_reverse_state_type m_statesMachine;
	Parms m_parms;
	Data m_data;
	hkVector2 m_samplingPoint;
	float m_samplingTime;
	bool m_isSampled;
	bool m_isReadyToGo;
	Result m_result;
	float m_reverseStartTime;

};





#endif